/**
 * QueryThread.java
 * Created at 2017-12-27
 * Created by zhanghailin
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.rms.monitor.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import com.broadtext.common.repository.EntityDao;

/**
 * <p>ClassName: QueryThread</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2017-12-27</p>
 */
public class QueryThread<T> implements Callable<List<T>> {
    
    private Map<String, Object> paramsMap;
    
    private EntityDao entityDao;
    
    private StringBuffer sqlAlis;
    
    public QueryThread(Map<String, Object> paramsMap, EntityDao entityDao,StringBuffer sqlAlis) {
        this.paramsMap = paramsMap;
        this.entityDao = entityDao;
        this.sqlAlis = sqlAlis;
    }

    /** (non-Javadoc)
     * <p>Title: call</p>
     * <p>Description: </p>
     * @return
     * @throws Exception
     * @see java.util.concurrent.Callable#call()
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<T> call() throws Exception {
        System.out.println("start query thread[query sqlAlis:"+sqlAlis+",packCode:"+paramsMap.get("packCode")+"gNo:"+paramsMap.get("gNo")+"]");
        long starTime=System.currentTimeMillis();
        List<T> list = new ArrayList<T>();
        list = entityDao.findByQuery(sqlAlis.toString(), paramsMap);
        long endTime=System.currentTimeMillis();
        long time=endTime-starTime;
        //System.out.println(time+":"+sqlAlis+":"+paramsMap.get("packCode")+" "+paramsMap.get("gNo"));
        System.out.println("end query thread[query sqlAlis:"+sqlAlis+",packCode:"+paramsMap.get("packCode")+",gNo:"+paramsMap.get("gNo")+",time:"+time+"]");
        return list;
    }

}
